<!--#include file="./header.inc"-->
<!--#include file="../core/upload.inc"-->
<%
' KindEditor ASP
' 本ASP程序是演示程序，建议不要直接在实际项目中使用。
' 如果您确定直接使用本程序，使用之前请仔细确认相关安全设置。
upFiles()
set re = nothing
set fso = nothing
function upFiles()
	dim aspUrl, savePath, saveUrl, maxSize, fileName, fileExt, newFileName, filePath, fileUrl, dirName
	dim imageExtStr, flashExtStr, mediaExtStr, fileExtStr
	dim upload, file, ranNum, hash, ymd, nowdir, t, result
	
	'aspUrl = fileName 'request.serverVariables("SCRIPT_NAME")
	'aspUrl = left(aspUrl, inStrRev(aspUrl, "/"))
	
	'文件保存目录路径
	savePath = root & uploadDir & "/"
	'文件保存目录URL
	saveUrl = root & uploadDir & "/"
	'定义允许上传的文件扩展名
	'imageExtStr = "gif|jpg|jpeg|jpe|bmp|png"
	'flashExtStr = "swf|flv"
	'mediaExtStr = "swf|flv|mp3|wav|wma|wmv|mid|avi|mpg|asf|rm|rmvb"
	fileExtStr = uploadType '"doc|docx|xls|xlsx|ppt|htm|html|txt|zip|rar|gz|bz2"
	'最大文件大小
	maxSize = uploadSize '5 * 1024 * 1024 '5M
	
	t = now()
	nowdir = savePath & year(t) & right("0" & month(t), 2) & right("0" & day(t), 2) & "/"
	call app.mkdir(nowdir)
	
	set upload = new AnUpLoad
	upload.Exe = uploadType
	upload.MaxSize = maxSize
	upload.FileDir = nowdir
	upload.GetData()
	if upload.errorID > 0 then showError(upload.description)
	
	set file = upload.files("imgFile")
	if file Is nothing then showError("请选择文件。")

	set result = file.saveToFile(nowdir, 0, false)
	if result.error then showError(file.Exception)

	filePath = server.mapPath(nowdir & file.filename)
	fileUrl = nowdir & file.filename
	
	set upload = NoThing
	set file = NoThing
	
	if not fso.fileExists(filePath) then showError("上传文件失败。")
	
	response.addHeader "content-Type", "application/json; charset=UTF-8"
	set hash = jsObject()
	hash("error") = 0
	hash("url") = fileUrl
	hash.flush
	response.end
end function

function showError(message)
	response.addHeader "content-Type", "application/json; charset=UTF-8"
	dim hash
	set hash = jsObject()
	hash("error") = 1
	hash("message") = message
	hash.flush
	response.end
end function
%>